package com.siashan.unipay4j.biz;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PayBizUtil {



    /**
     * 将应用列表转换成Map格式
     *
     * @param bizList 应用列表
     * @return 应用map
     */
    public static Map<String, PayBiz> transBizMap(List<PayBiz> bizList) {
        Map<String, PayBiz> tmplMap = new HashMap<>();
        if (null != bizList && !bizList.isEmpty()) {
            for (PayBiz biz : bizList) {
                tmplMap.put(biz.getBizCode(), biz);
            }
        }
        return tmplMap;
    }


    public static PayBiz getPayBiz(Map<String, PayBiz> bizMap,String bizCode) {
        PayBiz payBiz = bizMap.get(bizCode);
        if (null == payBiz) {
            throw new Unipay4jBizException("无效的bizCode，请检查业务配置");
        }
        return payBiz;
    }

    public static String getPayNotifyUrl(Map<String, PayBiz> bizMap,String bizCode) {
        return getPayBiz(bizMap,bizCode).getPayNotifyUrl();
    }

    public static String getRefundNotifyUrl(Map<String, PayBiz> bizMap,String bizCode) {
        return getPayBiz(bizMap,bizCode).getRefundNotifyUrl();
    }


}
